package com.gpStudy.design.proxy;

import sun.misc.ProxyGenerator;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Proxy;
public class ProxyTest {

    private volatile String s;

    public static void main(String[] args) {
        Iuser user = new UserImpl();
        InvocationHandler h = new DynamicProxy(user);
        Iuser proxy = (Iuser) Proxy.newProxyInstance(Iuser.class.getClassLoader(), new Class[]{Iuser.class}, h);

//        byte[] $Proxy0s = ProxyGenerator.generateProxyClass("$Proxy0", new Class[]{proxy.getClass()});
//        try {
//            FileOutputStream os = new FileOutputStream("E://$Proxy0.class");
//            os.write($Proxy0s);
//            os.close();
//
//        } catch (FileNotFoundException e) {
//            e.printStackTrace();
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
//
//        new ObjectInputStream(proxy);


        proxy.eat("苹果");
    }
}